package com.wanhau.quartz.simpleTrigger;

import java.util.Date;

import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.SimpleTrigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;

public class SimpleJobRun {

	public static void main(String[] args) {
		JobDetail jobDetail = JobBuilder.newJob(MyJob.class)
				.withIdentity("JobDetail1", "Group1")
				.build();
		Date date = new Date();
		date.setTime(date.getTime() + 3000);
		Date date2 = new Date();
		date2.setTime(date2.getTime() + 6000L);
		SimpleTrigger simpleTrigger = (SimpleTrigger) TriggerBuilder
				.newTrigger().withIdentity("SimpleTrigger", "Group1")
				.withSchedule(SimpleScheduleBuilder.repeatSecondlyForTotalCount(5).repeatSecondlyForever(2))
				.startAt(date)
				.endAt(date2)
				.build();

		SchedulerFactory factory = new StdSchedulerFactory();
		try {
			Scheduler scheduler = factory.getScheduler();
			scheduler.scheduleJob(jobDetail, simpleTrigger);
			scheduler.start();
		} catch (SchedulerException e) {
			e.printStackTrace();
		}
	}

}
